package com.tieunguyen.adapter;

import java.util.ArrayList;
import java.util.List;
import com.tieunguyen.beans.Story;
import com.tieunguyen.truyencuoi.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListStoriesAdapter extends BaseAdapter {

	private Context context;
	ArrayList<Story> stories;
	ViewGroup viewGroup;
	
	public ListStoriesAdapter (Context context, ArrayList<Story> stories){
		this.context = context;
		this.stories = stories;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return stories.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return stories.get(position);
	}

	@Override
	public long getItemId(int id) {
		// TODO Auto-generated method stub
		return id;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		// TODO Auto-generated method stub
		Story category = stories.get(position);
		if(convertView == null){
			LayoutInflater inflater = ((ActionBarActivity) context).getLayoutInflater();
			convertView = inflater.inflate(R.layout.list_item_stories,  viewGroup, false);
		}
		/*
		TextView title = (TextView)convertView.findViewById(R.id.title);
		ImageView imageView = (ImageView)convertView.findViewById(R.id.list_icon);
		Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.dangian);
		imageView.setImageBitmap(icon);
		title.setText(category.getName());
		*/
		
		TextView title = (TextView)convertView.findViewById(R.id.title);
		title.setText(category.getTitle());
		//ImageView imageView = (ImageView)convertView.findViewById(R.id.icon);
		//Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.dangian);
		//imageView.setImageBitmap(icon);
		return convertView;
	}

}
